package com.js.data.system.controller;


import com.js.data.common.api.CommonResult;
import com.js.data.system.annotation.Log;
import com.js.data.system.dto.LogoConfigDTO;
import com.js.data.system.service.ConfigService;
import com.js.data.system.vo.ConfigVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 系统logo配置
 */
@RestController
public class ConfigController {

    @Resource
    private ConfigService configService;


    /**
     * 系统logo配置
     *
     * @since 2020-10-15
     */
    @GetMapping(value = "/config/info", produces = "application/json; charset=utf-8")
    public CommonResult<ConfigVO> getConfig() {
        return CommonResult.success(configService.getLogoConfig());
    }


    /**
     * 保存系统logo配置
     *
     * @param logoConfigDTO 表单
     * @return void
     */
    @PreAuthorize("@perm.check('system:config:edit')")
    @Log(value = "保存系统logo配置")
    @PostMapping(value = "/config", produces = "application/json; charset=utf-8")
    public CommonResult<Void> saveConfig(@Valid @RequestBody LogoConfigDTO logoConfigDTO) {
        configService.saveConfig(logoConfigDTO);
        return CommonResult.success();

    }

}
